package com.lynx.system.service;

import com.lynx.system.beans.User;
import com.lynx.system.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserRepository userRepository;
    @Override
    public List<User> findAll(int index,int limit) {
        List<User> users = userRepository.selectAll((index - 1) * limit, limit);
        return users;
    }

    @Override
    public int findCount() {
        int count = userRepository.selectCount();
        return count;
    }

    @Override
    public User findById(long id) {
        User user = userRepository.selectById(id);
        return user;
    }

    @Override
    public int addUser(User user) {
        user.setRegisterdate(new Date());
        int result = userRepository.insertUser(user);
        return result;
    }

    @Override
    public int editUser(User user) {
        int result = userRepository.updateUser(user);
        return result;
    }

    @Override
    public int removeUser(int id) {
        int result = userRepository.deleteById(id);
        return result;
    }
}
